package com.qiyou.servlet;

import java.io.IOException;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.qiyou.dao.IRemindInfoDao;
import com.qiyou.dao.factory.DaoFactory;
import com.qiyou.entity.RemindInfo;

/**
 * Servlet 将消息标记为已读
 */
@WebServlet(name = "ReadRemind", urlPatterns = { "/ReadRemind" })
public class ReadRemindServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;

	/**
	 * @see HttpServlet#service(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		IRemindInfoDao remindInfoDao = DaoFactory.getRemindInfoDao();
		
		String strid = request.getParameter("id");
		
		long id = strid == null ? 0 : Long.parseLong(strid);
		
		try {
			RemindInfo info = DaoFactory.getRemindInfoDao().getRemindInfo(id);
			
			info.setState("Y");
			remindInfoDao.doUpdate(info);
			response.getWriter().print(true);
			
		} catch (SQLException e) {
			e.printStackTrace();
		}
	}

}
